package com.fly.studio.home.app.service.impl;

import com.fly.studio.home.app.component.ServerRelation;
import com.fly.studio.home.app.service.ServerService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 服务
 *
 * @author fuliying3
 * @date 2022/09/01 21:38:00
 */
@Service
public class ServerServiceImpl implements ServerService {

    @Override
    public List<ServerRelation> serverTree() {
        List<ServerRelation> childServerList = new ArrayList<>();
        List<Integer> lbsSerialNumberList = new ArrayList<>();
        lbsSerialNumberList.add(1);
        ServerRelation searchBar = new ServerRelation(2L, 2, "搜索栏", 2, lbsSerialNumberList, "SearchBarWorker", null);
        ServerRelation hotWord = new ServerRelation(3L, 2, "热搜词", 3, lbsSerialNumberList, "HotWordWorker", null);
        ServerRelation banner = new ServerRelation(4L, 2, "Banner", 4, lbsSerialNumberList, "BannerWorker", null);
        ServerRelation kingKong = new ServerRelation(5L, 2, "金刚区", 5, lbsSerialNumberList, "KingKongWorker", null);
        ServerRelation onePlusOne = new ServerRelation(6L, 2, "1+1", 6, lbsSerialNumberList, "OnePlusOneWorker", null);
        List<Integer> feedSerialNumberList = new ArrayList<>();
        feedSerialNumberList.add(8);
        ServerRelation popStore = new ServerRelation(9L, 4, "无界", 9, feedSerialNumberList, "PopStoreWorker", null);
        ServerRelation search = new ServerRelation(10L, 4, "搜索", 10, feedSerialNumberList, "SearchWorker", null);
        List<ServerRelation> feedChildServerList = new ArrayList<>();
        childServerList.add(searchBar);
        childServerList.add(hotWord);
        childServerList.add(banner);
        childServerList.add(kingKong);
        childServerList.add(onePlusOne);
        feedChildServerList.add(popStore);
        feedChildServerList.add(search);
        List<Integer> storeTypeSerialNumberList = new ArrayList<>();
        storeTypeSerialNumberList.add(7);
        ServerRelation feed = new ServerRelation(8L, 3, "feed流", 8, storeTypeSerialNumberList, "FeedWorker", feedChildServerList);
        List<ServerRelation> parentChildServerList = new ArrayList<>();
        parentChildServerList.add(feed);
        ServerRelation type = new ServerRelation(7L, 2, "类型", 7, lbsSerialNumberList, "StoreTypeWorker", parentChildServerList);
        childServerList.add(type);
        ServerRelation lbs = new ServerRelation(1L, 1, "LBS", 1, null, "LbsWorker", childServerList);
        List<ServerRelation> serverList = new ArrayList<>();
        serverList.add(lbs);
        return serverList;
    }

    @Override
    public List<ServerRelation> serverList() {
        List<Integer> lbsSerialNumberList = new ArrayList<>();
        lbsSerialNumberList.add(1);
        ServerRelation searchBar = new ServerRelation(2L, 2, "搜索栏", 2, lbsSerialNumberList, "SearchBarWorker", null);
        ServerRelation hotWord = new ServerRelation(3L, 2, "热搜词", 3, lbsSerialNumberList, "HotWordWorker", null);
        ServerRelation banner = new ServerRelation(4L, 2, "Banner", 4, lbsSerialNumberList, "BannerWorker", null);
        ServerRelation kingKong = new ServerRelation(5L, 2, "金刚区", 5, lbsSerialNumberList, "KingKongWorker", null);
        ServerRelation onePlusOne = new ServerRelation(6L, 2, "1+1", 6, lbsSerialNumberList, "OnePlusOneWorker", null);
        List<Integer> feedSerialNumberList = new ArrayList<>();
        feedSerialNumberList.add(8);
        ServerRelation popStore = new ServerRelation(9L, 4, "无界", 9, feedSerialNumberList, "PopStoreWorker", null);
        ServerRelation search = new ServerRelation(10L, 4, "搜索", 10, feedSerialNumberList, "SearchWorker", null);
        List<Integer> storeTypeSerialNumberList = new ArrayList<>();
        storeTypeSerialNumberList.add(7);
        ServerRelation feed = new ServerRelation(8L, 3, "feed流", 8, storeTypeSerialNumberList, "FeedWorker", null);
        ServerRelation type = new ServerRelation(7L, 2, "类型", 7, lbsSerialNumberList, "StoreTypeWorker", null);
        ServerRelation lbs = new ServerRelation(1L, 1, "LBS", 1, null, "LbsWorker", null);
        List<ServerRelation> serverList = new ArrayList<>();
        serverList.add(type);
        serverList.add(feed);
        serverList.add(searchBar);
        serverList.add(hotWord);
        serverList.add(banner);
        serverList.add(kingKong);
        serverList.add(onePlusOne);
        serverList.add(popStore);
        serverList.add(search);
        serverList.add(lbs);
        return serverList;
    }

    @Override
    public Map<Integer, List<ServerRelation>> serverMap() {
        return serverList().stream().collect(Collectors.groupingBy(ServerRelation::getLayers));
    }
}
